# coding=GBK
'''
Created on 2010-10-10

@author: Chine
'''
from django.contrib import admin
from django import forms
from ChineKingBlog.blog.models import *

editor_choose = {
    'cke': {
        'class': 'ckeditor',
        'js': ('WYSIWYG/ckeditor/ckeditor.js',)
    },
    'mce': {
        'class': 'mceEditor',
        'js': ('WYSIWYG/tinymce/jscripts/tiny_mce/tiny_mce.js', 'WYSIWYG/tinymce_setup/tinymce_setup.js',)
    },
    'grappelli':{
        'class': 'mceEditor',
        'js': ('admin/tinymce/jscripts/tiny_mce/tiny_mce.js', 'admin/tinymce_setup/tinymce_setup.js',)
    }
}

class ArticleTagInline(admin.TabularInline):
    model = Article_Tag
    
class CommentInline(admin.StackedInline):
    model = Comment

class CategoryAdmin(admin.ModelAdmin):
    list_display = ('name', 'slug', 'order')

class TagAdmin(admin.ModelAdmin):
    inlines = (ArticleTagInline,)
    prepopulated_fields = {"slug": ("name",)}
    
class CommentAdmin(admin.ModelAdmin):
    list_display = ('username', 'email_address', 'site', 'content', 'avatar', 'visible', 'weibo_comment_id',)
    list_per_page = 10
    
class MessageAdmin(admin.ModelAdmin):
    list_display = ('username', 'email_address', 'site', 'content', 'avatar', 'visible', 'weibo_id',)
    list_per_page = 10

class ArticleAdmin(admin.ModelAdmin):
    list_display = ('title', 'is_always_above', 'status', 'clicks', 'created', 'modified', 'weibo_id')
    list_filter = ('status', 'created', 'modified')
    prepopulated_fields = {"slug": ("title",)}
    search_fields = ('title', 'content')
    formfield_overrides = {
        models.TextField: {'widget': forms.Textarea(attrs={'class': editor_choose['grappelli']['class'], 'rows': '50'})},
    }
    fieldsets = [
        ('文章编辑', {'fields': ('title', 'slug', 'content',)}),
        ('日期', {'fields': ('created', 'modified')}),
        ('信息', {'fields': ('category', 'author', 'status', 'is_always_above', 'send_weibo')}),
    ]
    readonly_fields = ("created",)
    inlines = (ArticleTagInline, CommentInline,)
    list_per_page = 10
    ordering = ['-created']
    
    class Media:
        js = editor_choose['grappelli']['js']
 
class UserInfoAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.TextField: {'widget': forms.Textarea(attrs={'class': editor_choose['grappelli']['class']})},
    }    
    class Media:
        js = editor_choose['grappelli']['js']
        
admin.site.register(Article, ArticleAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(Tag, TagAdmin)
admin.site.register(Comment, CommentAdmin)
admin.site.register(User_Info, UserInfoAdmin)
admin.site.register(Message, MessageAdmin)